let book = {
  year_: 2017,
  edition: 1,
};

// 在get 和 set 方法中 return  year 或者 对 year 赋值是不合法的，会导致栈溢出

Object.defineProperty(book, "year", {
  get() {
    return this.year_;
  },
  set(newValue) {
    if (newValue > 2017) {
      this.year_ = newValue;
      this.edition = newValue - 2017;
    }
  },
});

console.log(book.year);

console.log(book.edition);

book.year = 2019;

console.log(book.year);

console.log(book.edition);

console.log(Object.getOwnPropertyDescriptors(Object.prototype));

console.log("--------");

console.log(Object.getOwnPropertyDescriptor(book, "year"));
